﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Reflection;

namespace Strategy.Calculation
{
    public class SimpleFactory
    {
        public static AbstractCalculation CreateCalculation(string operate)
        {
            AbstractCalculation calculation = null;
            //switch (operate)
            //{
            //    case "-":
            //        calculation = new Minus();
            //        break;
            //    case "+":
            //        calculation = new Plus();
            //        break;
            //    case "/":
            //        calculation = new Devision();
            //        break;
            //    case "*":
            //        calculation = new Mutiply();
            //        break;
            //    default:
            //        break; 
            //}

            string dllType = ConfigurationManager.AppSettings[operate];

            Assembly assembly = Assembly.Load(dllType.Split(',')[1]);
            Type type = assembly.GetType(dllType.Split(',')[0]);

            calculation = (AbstractCalculation)Activator.CreateInstance(type);
            return calculation;
        }
    }
}
